package playn.game.backgrounds;

import playn.core.Surface;
import playn.game.core.Game;

public class Snow {
	
	private static int AMOUNT_OF_POINTS=200;
	
	
	class Point {
		private float x;
		private float y;
		private byte c;
		
		public Point(int x,int y,byte color){
			this.x=x;
			this.y=y;
			this.c=color;
		}
		
		public void render(Surface surface){
			surface.setFillColor(c*256*256+c*256+c);
			surface.fillRect(x, y, 0.8f, 0.8f);
		}
	}
	
	private Point[] points = new Point[AMOUNT_OF_POINTS];
	
	
	public Snow(){
		for(int i=0;i<AMOUNT_OF_POINTS;i++){
		
			byte c=(byte)(Math.random()*255);
			int x=(int)(Math.random()*Game.SCREEN_WIDTH);
			int y=(int)(Math.random()*Game.SCREEN_HEIGHT);

			points[i]=new Point(x,y,c);
		}
	}


	public void render(Surface surface) {
		for(int i=0;i<AMOUNT_OF_POINTS;i++){
			Point point=points[i];
			point.x+=(Math.random()-0.5f)*((256-point.c)/(200));
			if(point.x<0){point.x+=Game.SCREEN_WIDTH;}
			if(point.x>Game.SCREEN_WIDTH-2){point.x-=Game.SCREEN_WIDTH;}
			
			point.y+=Math.random();
			if(point.y>Game.SCREEN_HEIGHT-2) {point.y-=Game.SCREEN_HEIGHT;}
			
			points[i].render(surface);
		}
	}
	
}
